<?php
class CommentControl extends Control {

    //显示评论列表
    function index() {
        C("debug",0);
        $db = K("comment");
        $total = $db->count(); //获得总条数
        $page=new page($total,"10",3,1);
        $data=$db->order("cmid desc")->findall($page->limit());
        $page=$page->show();
        // p($data);
        $this->assign("page",$page);
        $this->assign("data", $data);
        $this->display();
    }

    //显示已审核评论列表
    function yescom() {
        C("debug",0);
        $db = K("comment");
        $total = $db->where("comment.shenhe=1")->count(); //获得总条数
        $page=new page($total,"10",3,1);
        $data=$db->where("comment.shenhe=1")->order("cmid desc")->findall($page->limit());
        $page=$page->show();
        // p($data);
        $this->assign("page",$page);
        $this->assign("data", $data);
        $this->display();
    }

    //显示未审核评论列表
    function nocom() {
        C("debug",0);
        $db = K("comment");
        $total = $db->where("comment.shenhe=0")->count(); //获得总条数
        $page=new page($total,"10",3,1);
        $data=$db->where("comment.shenhe=0")->order("cmid desc")->findall($page->limit());
        $page=$page->show();
        // p($data);
        $this->assign("page",$page);
        $this->assign("data", $data);
        $this->display();
    }

    //删除评论
    function delcomment() {
        $cmid = $this->_get("cmid");
        // $tem=C("huihou");
        // var_dump(C("huishou"));die;
        if ($cmid) {
            $db = M("comment");
            $data = array(); //返回客户端的数据
            if ($db->find("cmid=" . $cmid)) {
                $db->del($cmid);  
                $data['stat'] = "success";
                $data['msg'] = "";
            } else {
                $data['stat'] = "error";
                $data['msg'] = "删除文章失败,请重试";
            }
            echo json_encode($data);exit;
        }
    }

    //审核评论
    function shenhecomment() {
        $cmid = $this->_get("cmid");
        // $tem=C("huihou");
        // var_dump(C("huishou"));die;
        if ($cmid) {
            $db = M("comment");
            $data = array(); //返回客户端的数据
            if ($db->find("cmid=" . $cmid)) {
                $_POST=array("cmid"=>$cmid,'shenhe'=>1);
                $db->update();
                $data['stat'] = "success";
                $data['msg'] = "";
            } else {
                $data['stat'] = "error";
                $data['msg'] = "删除文章失败,请重试";
            }
            echo json_encode($data);exit;
        }
    }


    //底部删除按钮
    function delall() {
        $c=isset($_GET['cmid'])?1:0;
        $cmid = $this->_get("cmid");
        $cmid = explode(',', $cmid);
        // $data['msg'] = var_dump($aid);
        // echo json_encode($data);exit;
        if ($c) {
            // $data['msg'] = $aid;
            // echo json_encode($data);exit;
            $data = array(); //返回客户端的数据
            foreach ($cmid as $v) {
                $db = M("comment");
                if ($db->find("cmid=" . $v)) {
                    $db->del($v);  
                    // $db->del($v);
                    $data['stat'] = "success";
                    $data['msg'] = "";
                }else {
                    $data['stat'] = "error";
                    $data['msg'] = "删除文章失败,请重试";
                }
            }
            echo json_encode($data);exit;
        }
    }


    /**
     * 向模板分配置栏目
     * @access  private
     */
    private function assignCategoryData() {
        $db = M("category");
        $result = $db->all();
        $data = Data::channel($result, "cid", "pid", 0, "", 2, "--");
        $this->assign("category", $data);
    }


    function gouwuche(){
       $data = array(
         "id" => 4, //商品ID
         "name"=>"后盾网PHP视频教程光盘",//商品名称
         "num" => 3, //商品数量
         "price" => 100, //商品价格
         "options" => array(//其他参数如价格、颜色、可以为数组或字符串
                 "color" => "red",
                 "size" => "L"
                  )
       );
      cart::add($data); //添加到购物车
      // p($_SESSION);


      $data=array(
         "sid"=>"05749ed3",//唯一sid，添加购物车时自动生成
         "num"=>50
      );
      Cart::update($data);

      p($_SESSION);
    }

}

?>
